package io.renren.modules.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.constant.Constant;
import io.renren.common.service.impl.BaseServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.blog.dao.BlogTagDao;
import io.renren.modules.blog.entity.BlogTagEntity;
import io.renren.modules.blog.dto.BlogTagDto;
import io.renren.modules.blog.service.BlogTagService;
import org.springframework.stereotype.Service;
import io.renren.common.page.PageData;
import lombok.AllArgsConstructor;

import java.util.Collections;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

/**
 * (BlogTagEntity)表服务实现类
 *
 * @author chy
 * @since 2024-06-20 17:33:31
 */
@AllArgsConstructor
@Service("blogTagService")
public class BlogTagServiceImpl extends BaseServiceImpl<BlogTagDao, BlogTagEntity> implements BlogTagService {


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BlogTagDto get(Long id) {
        return ConvertUtils.sourceToTarget(baseDao.selectById(id), BlogTagDto.class);
    }

    /**
     * 分页查询
     *
     * @param params 筛选条件
     * @return 查询结果
     */
    @Override
    public PageData<BlogTagDto> page(Map<String, Object> params) {
        IPage<BlogTagEntity> page = baseDao.selectPage(
                getPage(params, Constant.CREATE_DATE, false),
                getWrapper(params)
        );
        return getPageData(page, BlogTagDto.class);
    }

    private QueryWrapper<BlogTagEntity> getWrapper(Map<String, Object> params) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param blogTagDto 实例对象
     */
    @Transactional(rollbackFor = Exception.class)
    public void save(BlogTagDto blogTagDto) {
        BlogTagEntity entity = ConvertUtils.sourceToTarget(blogTagDto, BlogTagEntity.class);
        //保存角色
        insert(entity);
    }

    /**
     * 修改数据
     *
     * @param blogTagDto 实例对象
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(BlogTagDto blogTagDto) {
        BlogTagEntity entity = ConvertUtils.sourceToTarget(blogTagDto, BlogTagEntity.class);
        //更新角色
        updateById(entity);
    }

    /**
     * 通过主键删除数据
     *
     * @param ids 主键
     */

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long[] ids) {
        //删除角色
        baseDao.deleteBatchIds(Collections.singletonList(ids));
    }
}
